﻿using System.ComponentModel.DataAnnotations.Schema;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using OpenAdmin.Core.DbContextLocators;

namespace OpenAdmin.Core.Models;

[Table("Blogs")]
public class Blog : EntityBase<BloggingDbContextLocator>, IEntityTypeSeedDataConfigure<Blog>, IEntityTypeConfigure<Blog>
{
    public string Name { get; set; }
    public string Url { get; set; }
    public List<Post> Posts { get; set; } = new List<Post>();

    public void Configure(EntityTypeBuilder<Blog> builder)
    {
        builder.Property(x => x.Name).HasMaxLength(36);
        builder.Property(x => x.Url).HasMaxLength(36);
    }

    public IEnumerable<Blog> HasData(DbContext dbContext)
    {
        return new List<Blog>()
        {
           new Blog { Id = 1, Url = "http://blogs.msdn.com/adonet", Name = "黄厚镇" },
           new Blog { Id = 2, Url = "http://baidu.com", Name = "百度" }
        };
    }
}
